package exp;

import java.util.ArrayList;
import java.util.Hashtable;

import util.io.FileUtil;

public class CheckMissingTrigger {
	public static void main(String[] args){
		String[] lines = FileUtil.getTextFromFile("binding_err.log").split("\n");
		Hashtable<Integer, ArrayList<String>> fp = new Hashtable<Integer, ArrayList<String>>(),
		fn = new Hashtable<Integer, ArrayList<String>>();
		for (String line: lines){
			//[FP]  10089566#E13      Binding:"binding"[893-900] Theme:"IL-10"[915-920]
			Hashtable<Integer, ArrayList<String>> table = null;
			String[] items = line.split("\t");
			if (items[0].startsWith("[FP]")){
				table = fp;
			}
			else{
				table = fn;
			}
			int id = Integer.parseInt(items[0].substring(items[0].indexOf(" ")+1, items[0].indexOf("#")).trim());
			if (!table.containsKey(id))
				table.put(id, new ArrayList<String>());
			ArrayList<String> triggers = table.get(id);
			int start = items[1].indexOf("\"")+1;
			triggers.add(items[1].substring(start, items[1].indexOf("\"", start)));
		}
		int missing = 0, all = 0;
		for (Integer id: fn.keySet()){
			all += fn.get(id).size();
			if (!fp.containsKey(id)){
				missing += fn.get(id).size();
				for (String t:fn.get(id)){
					System.err.println("[MISSING] "+id+" "+t);
				}
			}
			else{
				missing += fn.get(id).size();
				for (String trigger: fn.get(id)){
					boolean found = false;
					for (String trigger2: fp.get(id)){
						if (trigger.toLowerCase().contains(trigger2)){
							missing --;
							found = true;
							break;
						}
					}
					if (!found){
						System.err.println("[MISSING] "+id+" "+trigger);
					}
				}
			}
		}
		System.out.println(missing +"   "+all);
	}
}
